
export function getCookie(cookieName) {
    var strCookie = document.cookie;
    var arrCookie = strCookie.split("; ");
    for (var i = 0; i < arrCookie.length; i++) {
        var arr = arrCookie[i].split("=");
        if (cookieName == arr[0]) {
            return arr[1];
        }
    }
    return "";
}


export function isFormData(v) {
    return Object.prototype.toString.call(v) === '[object FormData]';
}

export function routerWideTraversal(node) {
    let stack = node,
        data = [];
    while (stack.length != 0) {
        let shift = stack.shift();
        data.push(stack.path)
        let children = shift.children
        if (children) {
            for (let i = 0; i < children.length; i++) {
                stack.push(children[i])
            }
        }
    }
    return data
}

export function scroll(ele) {
	const scrollPart = document.querySelector(ele); // 目标节点的id或class
	const top = scrollPart.getBoundingClientRect().top - 50;
	const pageY = window.pageYOffset;
	const endPosition = top + pageY;

	const startTime = +new Date();
	const duration = 500; //ms

	function run() {
		const time = +new Date() - startTime;

		window.scrollTo(0, pageY + top * (time / duration));
		run.timer = requestAnimationFrame(run);

		if (time >= duration) {
			window.scrollTo(0, endPosition);
			cancelAnimationFrame(run.timer);
		}
	}
	requestAnimationFrame(run);
}